package chapter.sixth.item30;

enum PayRollDay {
	MONDAY(PayType.WEEKDAY),TUESDAY(PayType.WEEKDAY),
	WEDNESDAY(PayType.WEEKDAY),THUESDAY(PayType.WEEKDAY),
	FRIDAY(PayType.WEEKDAY),SATURDAY(PayType.WEEKEND),
	SUNDAY(PayType.WEEKEND);
	
	private final PayType payType;
	
	PayRollDay(PayType payType){
		this.payType = payType;
	}
	
	double pay(double hrs,double payRate){
		return payType.pay(hrs, payRate);
	}
	
	//策略枚举类
	private enum PayType{
		WEEKDAY{
			@Override
			double overtimePay(double hrs, double payRate) {
				return hrs<=HOURS_PER_SHIFT?0:
					(hrs-HOURS_PER_SHIFT)*payRate/2;
			}
		},
		WEEKEND{
			@Override
			double overtimePay(double hrs, double payRate) {
				return hrs*payRate/2;
			}
		};
		
		private static final int HOURS_PER_SHIFT = 8;
		
		abstract double overtimePay(double hrs,double payRate);
		
		double pay(double hrs,double payRate){
			double basePay = hrs*payRate;
			return basePay+overtimePay(hrs,payRate);
		}
	}
}
